package test;


public class Dfs {
	//1.传计数器
	public ListNode dfs1(ListNode head,int count){
        if(head==null) return head;
        ListNode cur=dfs1(head.next,count+1);
        if(count%2==0&&cur!=null){
            head.next=cur.next;
            cur.next=head;
            return cur;
        }
        else{
            head.next=cur;
            return head;
        }
    }
	//2.只处理要处理的位置
	public ListNode dfs2(ListNode head){
        if(head==null ||head.next==null) return head;
        ListNode cur=dfs2(head.next.next);
        ListNode tmp=head.next;
        tmp.next=head;
        head.next=cur;
        return tmp;
    }
    public ListNode swapPairs(ListNode head) {
        return dfs2(head);
    }
}
